package Dungeon;


import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Iterator;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import squarePackage.PlainSquare;
import squarePackage.RockSquare;
import squarePackage.Square;
import squarePackage.SquareImp;
import squarePackage.TeleportPlainSquare;
import Enumerations.Directions;
import Enumerations.Temperature;
import Exceptions.IllegalDimensionException;
import Exceptions.IllegalDungeonException;
import Obstacle.Door;
import Obstacle.Wall;

public class CompositeDungeonsTest {

	CompositeDungeon<PlainSquare> compo; 
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		compo =new CompositeDungeon<PlainSquare>(10000, 10000, 10000);
	}

	@After
	public void tearDown() throws Exception {
	}
	
	
	@Test
	public final void getModifiedDistancesTest() throws IllegalDimensionException{
		Level<PlainSquare> level = new Level<PlainSquare>(10,10,10,5);
		
		CompositeDungeon<PlainSquare> compo2 = new CompositeDungeon<PlainSquare>(1000, 1000, 1000);
		Level<PlainSquare> level2 = new Level<PlainSquare>(10,10,10,8);
		Shaft<PlainSquare> shaft2 = new Shaft<PlainSquare>(10,10,10,10,10,-4);
		
		CompositeDungeon<PlainSquare> compo3 = new CompositeDungeon<PlainSquare>(100, 100, 100);
		Shaft<PlainSquare> shaft3 = new Shaft<PlainSquare>(10, 10, 10, 9, 9, -5);
		
		try {
			
			
			compo3.addDungeonToCompositeDungeon(6, 6, 0, shaft3);
			compo2.addDungeonToCompositeDungeon(5, 5, 0, compo3);
			compo2.addDungeonToCompositeDungeon(3, 3, 0, level2);
			compo2.addDungeonToCompositeDungeon(4, 4, 0, shaft2);
			compo.addDungeonToCompositeDungeon(2, 2, 0, compo2);
			compo.addDungeonToCompositeDungeon(1, 1, 0, level);
		
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

		
		
	}
	
	@Test
	public final void getallCoordinatesAndSquareTest() throws IllegalDimensionException{
		Level<PlainSquare> level = new Level<PlainSquare>(10,10,10,5);
		
		CompositeDungeon<PlainSquare> compo2 = new CompositeDungeon<PlainSquare>(1000, 1000, 1000);
		Level<PlainSquare> level2 = new Level<PlainSquare>(10,10,10,8);
		Shaft<PlainSquare> shaft2 = new Shaft<PlainSquare>(10,10,10,10,10,-4);
		
		CompositeDungeon<PlainSquare> compo3 = new CompositeDungeon<PlainSquare>(100, 100, 100);
		Shaft<PlainSquare> shaft3 = new Shaft<PlainSquare>(10, 10, 10, 9, 9, -5);
		
		try {
			
			
			
			compo3.addDungeonToCompositeDungeon(6, 6, 0, shaft3);
			compo2.addDungeonToCompositeDungeon(5, 5, 0, compo3);
			compo2.addDungeonToCompositeDungeon(3, 3, 0, level2);
			compo2.addDungeonToCompositeDungeon(4, 4, 0, shaft2);
			compo.addDungeonToCompositeDungeon(2, 2, 0, compo2);
			compo.addDungeonToCompositeDungeon(1, 1, 0, level);
			
			PlainSquare plain = new PlainSquare();
			PlainSquare plain3 = new PlainSquare();
			
			plain.setMaterial(false);
			plain3.setMaterial(false);
			
			shaft3.addSquareToDungeon(9, 9, 0, plain3);
			level.addSquareToDungeon(1, 1, 5, plain);
			
			
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}
	
	@Test
	public final void canHaveAsDungeonCoordinateTest() throws IllegalDimensionException{
		Level<PlainSquare> level = new Level<PlainSquare>(10,10,10,5);
		try {
			compo.addDungeonToCompositeDungeon(1, 1, 0, level);
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalDimensionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		assertFalse(compo.canHaveAsDungeonCoordinate(1, 1, 0));
		assertTrue(compo.canHaveAsDungeonCoordinate(2, 1, 0));
	}
	
	@Test
	public final void canHaveAsDungeonTesting() throws IllegalDimensionException{
		Level<PlainSquare> level = new Level<PlainSquare>(10,10,10,5);
		assertFalse(compo.isValidDungeonDimensions(9995, 9995, 9995, level));
		
		
	}
	
	@Test
	public final void canHaveAsDungeonAtCoordinateTesting() throws IllegalDimensionException{
		
		Level<PlainSquare> level = new Level<PlainSquare>(10,10,10,5);
		
		CompositeDungeon<PlainSquare> compo2 = new CompositeDungeon<PlainSquare>(1000, 1000, 100);
		Level<PlainSquare> level2 = new Level<PlainSquare>(10,10,10,8);
		Shaft<PlainSquare> shaft2 = new Shaft<PlainSquare>(10,10,10,10,10,-4);
		
		CompositeDungeon<PlainSquare> compo3 = new CompositeDungeon<PlainSquare>(100, 100, 100);
		Shaft<PlainSquare> shaft3 = new Shaft<PlainSquare>(10, 10, 10, 9, 9, -5);
		
		try {
		
			compo3.addDungeonToCompositeDungeon(6, 6, 0, shaft3);
			compo2.addDungeonToCompositeDungeon(5, 5, 0, compo3);
			compo2.addDungeonToCompositeDungeon(3, 3, 0, level2);
			compo2.addDungeonToCompositeDungeon(4, 4, 0, shaft2);
			compo.addDungeonToCompositeDungeon(2, 2, 0, compo2);
			compo.addDungeonToCompositeDungeon(1, 1, 0, level);
			
			PlainSquare plain = new PlainSquare();
			PlainSquare plain3 = new PlainSquare();
			
			plain.setMaterial(false);
			plain3.setMaterial(false);
			
			shaft3.addSquareToDungeon(9, 9, 0, plain3);
			level.addSquareToDungeon(1, 1, 5, plain);
			
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Level<PlainSquare> newLevel= new Level<PlainSquare>(50,50,10,0);
		PlainSquare plainnewLevel = new PlainSquare();
		plainnewLevel.setMaterial(false);
		newLevel.addSquareToDungeon(12, 12, 0, plainnewLevel);
		
		assertFalse(compo.areThereOverlappingSquares(10, 10, 0, newLevel));
	}
	
	@Test
	public final void createSpacesTest() throws IllegalDimensionException{
		Level<PlainSquare> level = new Level<PlainSquare>(10, 10, 10, 0);
		
		CompositeDungeon<PlainSquare> compo2 = new CompositeDungeon<PlainSquare>(100, 100, 100);
		
		Level<PlainSquare> level2 = new Level<PlainSquare>(10, 10, 10, 0);
		
		try {
			compo2.addDungeonToCompositeDungeon(0, 1, 0, level2);
			compo.addDungeonToCompositeDungeon(1, 2, 0, compo2);
			compo.addDungeonToCompositeDungeon(1, 1, 0, level);
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		PlainSquare plainlevel1 = new PlainSquare();
		PlainSquare plainlevel1again = new PlainSquare();
		PlainSquare plainlevel2 = new PlainSquare();
		PlainSquare plainlevel2again = new PlainSquare();
		plainlevel1.setMaterial(false);
		plainlevel1again.setMaterial(false);
		plainlevel2.setMaterial(false);
		plainlevel2again.setMaterial(false);
		
		
		level.addSquareToDungeon(0, 1, 0, plainlevel1);
		level.addSquareToDungeon(0, 2, 0, plainlevel1again);
		level2.addSquareToDungeon(0, 1, 0, plainlevel2);
		level2.addSquareToDungeon(0, 2, 0, plainlevel2again);


		compo.createSpaces();
		assertTrue(compo.isReachable(plainlevel1, plainlevel2again));
	}
	
	@Test
	public final void addSquareTesting() throws IllegalDimensionException{
		Level<PlainSquare> level = new Level<PlainSquare>(10, 10, 10, 0);

		CompositeDungeon<PlainSquare> compo2 = new CompositeDungeon<PlainSquare>(100, 100, 100);
		
		Level<PlainSquare> level2 = new Level<PlainSquare>(10, 10, 10, 0);
		
		try {
			compo2.addDungeonToCompositeDungeon(0, 1, 0, level2);
			compo.addDungeonToCompositeDungeon(1, 2, 0, compo2);
			compo.addDungeonToCompositeDungeon(1, 1, 0, level);
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		PlainSquare plainlevel1 = new PlainSquare();
		PlainSquare plainlevel1again = new PlainSquare();
		PlainSquare plainlevel2 = new PlainSquare();
		PlainSquare plainlevel2again = new PlainSquare();
		plainlevel1.setMaterial(false);
		plainlevel1again.setMaterial(false);
		plainlevel2.setMaterial(false);
		plainlevel2again.setMaterial(false);
		
		
		level.addSquareToDungeon(0, 1, 0, plainlevel1);
		level.addSquareToDungeon(0, 2, 0, plainlevel1again);
		level2.addSquareToDungeon(0, 1, 0, plainlevel2);
		level2.addSquareToDungeon(0, 2, 0, plainlevel2again);
		
		
		assertFalse(compo.canHaveAsSquare(plainlevel1));
		assertFalse(compo.canHaveAsCoordinate(1, 3, 0));
		
		PlainSquare plaintest = new PlainSquare();
		plaintest.setMaterial(false);
		
		compo.addSquareToDungeon(1, 6, 0,plaintest);
		assertTrue(compo.getAllSquaresInDungeon().contains(plaintest));
		assertTrue(level2.getAllSquaresInDungeon().contains(plaintest));
		assertTrue(compo.isReachable(plainlevel2, plaintest));

	}
	
	@Test
	public final void addSquareTestIfBordersEverywhereAReAdjusted() throws IllegalDimensionException{
		CompositeDungeon<PlainSquare> composite = new CompositeDungeon<PlainSquare>(100, 100, 100);
		
		Level<PlainSquare> level110 = new Level<PlainSquare>(10,10,10,0);
		Level<PlainSquare> level410 = new Level<PlainSquare>(10,10,10,0);
		
		PlainSquare square1 = new PlainSquare();
		PlainSquare square2 = new PlainSquare();
		PlainSquare square3 = new PlainSquare();
		PlainSquare square4 = new PlainSquare();
		square1.setMaterial(false);
		square2.setMaterial(false);
		square3.setMaterial(false);	
		square4.setMaterial(false);
		
		square3.setBorder(Directions.West, new Wall());
		
		square1.setBorder(Directions.East, new Wall(new Door()));
		
		level110.addSquareToDungeon(2, 1, 0, square1);
		level110.addSquareToDungeon(1, 1, 0, square2);
		try {
			composite.addDungeonToCompositeDungeon(1, 1, 0, level110);
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		composite.addSquareToDungeon(4, 2, 0, square3);
		assertEquals(square1.getBorderByDirection(Directions.East), square3.getBorderByDirection(Directions.West));
		level110.removeSquareFromDungeon(square3);
		assertFalse(composite.getAllSquaresInDungeon().contains(square3));
		
		square4.setBorder(Directions.West, new Wall());
		
		level410.addSquareToDungeon(0, 1, 0, square4);
		
		
		try {
			composite.addDungeonToCompositeDungeon(4, 1, 0, level410);
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		assertEquals(square1.getBorderByDirection(Directions.East), square4.getBorderByDirection(Directions.West));
				
		square4.deleteBorder(Directions.West);
		square1.deleteBorder(Directions.East);
		composite.createSpaces();
		assertTrue(composite.isReachable(square2, square4));
		composite.removeSquareFromDungeon(square1);
		assertFalse(composite.isReachable(square2, square4));
		
	}
	
	@Test
	public final void removeBorderFromSquareInCompositeDungeon() throws IllegalDimensionException{
		CompositeDungeon<PlainSquare> composite = new CompositeDungeon<PlainSquare>(100, 100, 100);
		
		Level<PlainSquare> level110 = new Level<PlainSquare>(10,10,10,0);
		Level<PlainSquare> level410 = new Level<PlainSquare>(10,10,10,0);
		
		PlainSquare square1 = new PlainSquare();
		PlainSquare square2 = new PlainSquare();
		PlainSquare square3 = new PlainSquare();
		PlainSquare square4 = new PlainSquare();
		square1.setMaterial(false);
		square2.setMaterial(false);
		square3.setMaterial(false);	
		square4.setMaterial(false);
		
		square3.setBorder(Directions.West, new Wall());
		
		square1.setBorder(Directions.East, new Wall(new Door()));
		
		level110.addSquareToDungeon(2, 1, 0, square1);
		level110.addSquareToDungeon(1, 1, 0, square2);
		try {
			composite.addDungeonToCompositeDungeon(1, 1, 0, level110);
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		composite.addSquareToDungeon(4, 2, 0, square3);
		assertEquals(square1.getBorderByDirection(Directions.East), square3.getBorderByDirection(Directions.West));
		level110.removeSquareFromDungeon(square3);
		assertFalse(composite.getAllSquaresInDungeon().contains(square3));
		
		square4.setBorder(Directions.West, new Wall());
		
		level410.addSquareToDungeon(0, 1, 0, square4);
		
		
		try {
			composite.addDungeonToCompositeDungeon(4, 1, 0, level410);
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		square4.setBorder(Directions.East, new Wall());
		composite.removeBorderFromSquareInDungeon(square4, Directions.East);
		assertFalse(square4.hasBorder(Directions.East));
	
	
	}
	
	@Test
	public final void addBorderToSquareInCompositeDungeon() throws IllegalDimensionException{
		CompositeDungeon<PlainSquare> composite = new CompositeDungeon<PlainSquare>(100, 100, 100);
		
		Level<PlainSquare> level110 = new Level<PlainSquare>(10,10,10,0);
		Level<PlainSquare> level410 = new Level<PlainSquare>(10,10,10,0);
		
		PlainSquare square1 = new PlainSquare();
		PlainSquare square2 = new PlainSquare();
		PlainSquare square3 = new PlainSquare();
		PlainSquare square4 = new PlainSquare();
		square1.setMaterial(false);
		square2.setMaterial(false);
		square3.setMaterial(false);	
		square4.setMaterial(false);
		
		square3.setBorder(Directions.West, new Wall());
		
		square1.setBorder(Directions.East, new Wall(new Door()));
		
		level110.addSquareToDungeon(2, 1, 0, square1);
		level110.addSquareToDungeon(1, 1, 0, square2);
		try {
			composite.addDungeonToCompositeDungeon(1, 1, 0, level110);
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		composite.addSquareToDungeon(4, 2, 0, square3);
		assertEquals(square1.getBorderByDirection(Directions.East), square3.getBorderByDirection(Directions.West));
		level110.removeSquareFromDungeon(square3);
		assertFalse(composite.getAllSquaresInDungeon().contains(square3));
		
		square4.setBorder(Directions.West, new Wall());
		
		level410.addSquareToDungeon(0, 1, 0, square4);
		
		try {
			composite.addDungeonToCompositeDungeon(4, 1, 0, level410);
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		square4.setBorder(Directions.East, new Wall());
		composite.removeBorderFromSquareInDungeon(square4, Directions.East);
		assertFalse(square4.hasBorder(Directions.East));
	
		composite.addBorderToSquareInDungeon(square4, Directions.North, new Wall(new Door()));
		assertTrue(square4.getBorderByDirection(Directions.North).hasDoor());
	
	}
	
	@Test
	public final void removeDungeonFromDungeonTest() throws IllegalDimensionException{
	Level<PlainSquare> level = new Level<PlainSquare>(10,10,10,5);
		
		CompositeDungeon<PlainSquare> compo2 = new CompositeDungeon<PlainSquare>(1000, 1000, 1000);
		Level<PlainSquare> level2 = new Level<PlainSquare>(10,10,10,8);
		
		CompositeDungeon<PlainSquare> compo3 = new CompositeDungeon<PlainSquare>(100, 100, 100);
		Shaft<PlainSquare> shaft3 = new Shaft<PlainSquare>(10, 10, 10, 10, 10, -5);
		
		try {
			compo3.addDungeonToCompositeDungeon(5, 5, 0, shaft3);
			compo2.addDungeonToCompositeDungeon(4, 4, 0, compo3);
			compo2.addDungeonToCompositeDungeon(3, 3, 0, level2);
			compo.addDungeonToCompositeDungeon(1, 1, 0, level);
			compo.addDungeonToCompositeDungeon(2, 2, 0, compo2);
					
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		assertTrue(compo.getAllDungeons().contains(level));
		assertTrue(compo.getAllDungeons().contains(level2));
		assertTrue(compo.getAllDungeons().contains(compo2));
		assertTrue(compo.getAllDungeons().contains(compo3));
		assertTrue(compo.getAllDungeons().contains(shaft3));
		
		try {
			compo3.removeDungeonFromDungeon(shaft3);
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		assertFalse(compo.getAllDungeons().contains(shaft3));
		
		try {
			compo.removeDungeonFromDungeon(compo2);
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		assertTrue(compo.getAllDungeons().contains(level));
		assertFalse(compo.getAllDungeons().contains(level2));
		assertFalse(compo.getAllDungeons().contains(compo2));
		assertFalse(compo.getAllDungeons().contains(compo3));
		assertFalse(compo.getAllDungeons().contains(shaft3));
		
		
		
		
	}
	
	@Test
	public final void iteratorTest() throws IllegalDimensionException{

		Level<PlainSquare> level = new Level<PlainSquare>(10,10,10,5);
		
		CompositeDungeon<PlainSquare> compo2 = new CompositeDungeon<PlainSquare>(1000, 1000, 100);
		Level<PlainSquare> level2 = new Level<PlainSquare>(10,10,10,8);
		Shaft<PlainSquare> shaft2 = new Shaft<PlainSquare>(10,10,10,10,10,-4);
		
		CompositeDungeon<PlainSquare> compo3 = new CompositeDungeon<PlainSquare>(100, 100, 100);
		Shaft<PlainSquare> shaft3 = new Shaft<PlainSquare>(10, 10, 10, 9, 9, -5);
		
		try {
		
			compo3.addDungeonToCompositeDungeon(6, 6, 0, shaft3);
			compo2.addDungeonToCompositeDungeon(5, 5, 0, compo3);
			compo2.addDungeonToCompositeDungeon(3, 3, 0, level2);
			compo2.addDungeonToCompositeDungeon(4, 4, 0, shaft2);
			compo.addDungeonToCompositeDungeon(2, 2, 0, compo2);
			compo.addDungeonToCompositeDungeon(1, 1, 0, level);
			
			PlainSquare plain = new PlainSquare();
			PlainSquare plain3 = new PlainSquare();
			
			plain.setMaterial(false);
			plain3.setMaterial(false);
			
			PlainSquare s2 = new PlainSquare();
			System.out.println(s2 + "In composite2");
			s2.setMaterial(false);
			shaft2.addSquareToDungeon(10, 10, 1, s2);
			
			System.out.println(plain3 + "In composite3 shaft3");
			shaft3.addSquareToDungeon(9, 9, 0, plain3);
			System.out.println(plain + "In composite level");
			level.addSquareToDungeon(1, 1, 5, plain);
			
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	
	System.out.println("ZONDER ITERATOR");
	for(Object element : compo.getAllSquaresInDungeon()){
	System.out.println(element);
	}

System.out.println("                                              ");
	System.out.println("MET ITERATOR");
	Iterator<PlainSquare> it = compo.iterator();
	while(it.hasNext()){
	
		Square square =(Square) it.next();
		if(square != null){
			System.out.println(square);
		}
	}		
		
	}

	@Test
	public final void testSquareAdding() throws IllegalDimensionException, IllegalDungeonException{
		CompositeDungeon<PlainSquare> dungeon =new CompositeDungeon<PlainSquare>(100, 100, 100);
		PlainSquare square1 = new PlainSquare();
		square1.setMaterial(false);
		
		PlainSquare square2 = new PlainSquare();
		square2.setMaterial(false);
		
		ArrayList<SquareImp> list = new ArrayList<SquareImp>();
		list.add(new PlainSquare());
		TeleportPlainSquare square3 = new TeleportPlainSquare(list);
		square3.setMaterial(false);
		
		Level<PlainSquare> translevel = new Level<PlainSquare>(20, 20, 20, 0);
		dungeon.addDungeonToCompositeDungeon(1, 0, 0, translevel);
		
		
		try {
			dungeon.addSquareToDungeon(10, 5, 0, square1);
			dungeon.addSquareToDungeon(10, 6, 0, square3);
			dungeon.addSquareToDungeon(10, 7, 0, square2);
		} catch (IllegalDimensionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println(dungeon.getCoordinatesAndSquaresInDungeon());
		
		System.out.println(dungeon.getListOfSpaces());
		
	}	
	
	@Test
	public final void getRootTesting() throws IllegalDimensionException{
		Level<SquareImp> level = new Level<SquareImp>(10,10,10,5);
		
		CompositeDungeon<SquareImp> compo = new CompositeDungeon<SquareImp>(100000, 100000, 100000);
		
		CompositeDungeon<SquareImp> compo2 = new CompositeDungeon<SquareImp>(1000, 1000, 100);
		Level<SquareImp> level2 = new Level<SquareImp>(10,10,10,8);
		Shaft<SquareImp> shaft2 = new Shaft<SquareImp>(10,10,10,10,10,-4);
		
		CompositeDungeon<SquareImp> compo3 = new CompositeDungeon<SquareImp>(100, 100, 100);
		Shaft<SquareImp> shaft3 = new Shaft<SquareImp>(10, 10, 10, 9, 9, -5);
		
		assertEquals(level.getRoot(), level);
		assertEquals(compo2, compo2.getRoot());
		assertEquals(level2, level2.getRoot());
		assertEquals(shaft3, shaft3.getRoot());
		assertEquals(compo3, compo3.getRoot());
		
		try {
		
			
			compo3.addDungeonToCompositeDungeon(6, 6, 0, shaft3);
			assertEquals(compo3, shaft3.getRoot());
			
			compo2.addDungeonToCompositeDungeon(5, 5, 0, compo3);
			
			
			compo2.addDungeonToCompositeDungeon(3, 3, 0, level2);
			
			compo2.addDungeonToCompositeDungeon(4, 4, 0, shaft2);
			assertEquals(compo2, compo2.getRoot());
			assertEquals(compo2, shaft3.getRoot());
			assertEquals(compo2, level2.getRoot());
			
			
			compo.addDungeonToCompositeDungeon(2, 2, 0, compo2);
			compo.addDungeonToCompositeDungeon(1, 1, 0, level);
			assertEquals(compo, compo2.getRoot());
			assertEquals(compo, level.getRoot());
			
			assertEquals(compo, shaft2.getRoot());
			assertEquals(compo, level2.getRoot());
			assertEquals(compo, compo3.getRoot());
			assertEquals(compo, shaft3.getRoot());
			
			assertTrue(compo.getAllDungeons().contains(compo2));
			
		}
		catch (Exception e){
			e.printStackTrace();
		}
				
		assertEquals(compo, shaft3.getRoot());
	
			
	}

	@Test
	public final void getContainginDungeonTesting() throws IllegalDimensionException{
		Level<SquareImp> level = new Level<SquareImp>(10,10,10,5);
		
		CompositeDungeon<SquareImp> compo = new CompositeDungeon<SquareImp>(100000, 100000, 100000);
		
		CompositeDungeon<SquareImp> compo2 = new CompositeDungeon<SquareImp>(1000, 1000, 100);
		Level<SquareImp> level2 = new Level<SquareImp>(10,10,10,8);
		Shaft<SquareImp> shaft2 = new Shaft<SquareImp>(10,10,10,10,10,-4);
		
		CompositeDungeon<SquareImp> compo3 = new CompositeDungeon<SquareImp>(100, 100, 100);
		Shaft<SquareImp> shaft3 = new Shaft<SquareImp>(10, 10, 10, 9, 9, -5);
		
	
		
		try {
		
			compo3.addDungeonToCompositeDungeon(6, 6, 0, shaft3);
			compo2.addDungeonToCompositeDungeon(5, 5, 0, compo3);
			compo2.addDungeonToCompositeDungeon(3, 3, 0, level2);
			compo2.addDungeonToCompositeDungeon(4, 4, 0, shaft2);
			compo.addDungeonToCompositeDungeon(2, 2, 0, compo2);
			compo.addDungeonToCompositeDungeon(1, 1, 0, level);
			
		}
		catch (Exception e){
			e.printStackTrace();
		}
				
		assertEquals(shaft3.getContainingDungeon(), compo3);
		assertEquals(level2.getContainingDungeon(), compo2);
			
	}
	
	@Test
	public final void removeDungeonTesting() throws IllegalDimensionException, IllegalDungeonException{
Level<SquareImp> level = new Level<SquareImp>(10,10,10,5);
		
		CompositeDungeon<SquareImp> compo = new CompositeDungeon<SquareImp>(100000, 100000, 100000);
		
		CompositeDungeon<SquareImp> compo2 = new CompositeDungeon<SquareImp>(1000, 1000, 100);
		Level<SquareImp> level2 = new Level<SquareImp>(10,10,10,8);
		Shaft<SquareImp> shaft2 = new Shaft<SquareImp>(10,10,10,10,10,-4);
		
		CompositeDungeon<SquareImp> compo3 = new CompositeDungeon<SquareImp>(100, 100, 100);
		Shaft<SquareImp> shaft3 = new Shaft<SquareImp>(10, 10, 10, 9, 9, -5);
		
	
		
		try {
		
			compo3.addDungeonToCompositeDungeon(6, 6, 0, shaft3);
			compo2.addDungeonToCompositeDungeon(5, 5, 0, compo3);
			compo2.addDungeonToCompositeDungeon(3, 3, 0, level2);
			compo2.addDungeonToCompositeDungeon(4, 4, 0, shaft2);
			compo.addDungeonToCompositeDungeon(2, 2, 0, compo2);
			compo.addDungeonToCompositeDungeon(1, 1, 0, level);
			
		}
		catch (Exception e){
			e.printStackTrace();
		}
		
		assertEquals(shaft3.getRoot(), compo);
		System.out.println(shaft3.getRoot());
		compo.removeDungeonFromDungeon(compo2);
		assertTrue(compo2.isTerminated());
		assertEquals(shaft3, shaft3.getRoot());

			
	}
	

	@Test
	public final void terminateTesting() throws IllegalDimensionException, IllegalDungeonException{
		Level<SquareImp> level = new Level<SquareImp>(10,10,10,5);
		
		CompositeDungeon<SquareImp> compo = new CompositeDungeon<SquareImp>(100000, 100000, 100000);
		
		CompositeDungeon<SquareImp> compo2 = new CompositeDungeon<SquareImp>(1000, 1000, 100);
		Level<SquareImp> level2 = new Level<SquareImp>(10,10,10,8);
		Shaft<SquareImp> shaft2 = new Shaft<SquareImp>(10,10,10,10,10,-4);
		
		CompositeDungeon<SquareImp> compo3 = new CompositeDungeon<SquareImp>(100, 100, 100);
		Shaft<SquareImp> shaft3 = new Shaft<SquareImp>(10, 10, 10, 9, 9, -5);
		
	
		
		try {
		
			compo3.addDungeonToCompositeDungeon(6, 6, 0, shaft3);
			compo2.addDungeonToCompositeDungeon(5, 5, 0, compo3);
			compo2.addDungeonToCompositeDungeon(3, 3, 0, level2);
			compo2.addDungeonToCompositeDungeon(4, 4, 0, shaft2);
			compo.addDungeonToCompositeDungeon(2, 2, 0, compo2);
			compo.addDungeonToCompositeDungeon(1, 1, 0, level);
			
		}
		catch (Exception e){
			e.printStackTrace();
		}
		
		compo.terminate();
		assertTrue(compo.isTerminated());
		assertTrue(shaft3.isTerminated());
		
		assertEquals(shaft3, shaft3.getRoot());
			
	}
	
	
	@Test
	public final void removraw() throws IllegalDimensionException, IllegalDungeonException{
		Level<SquareImp> level = new Level<SquareImp>(10,10,10,5);
		
		CompositeDungeon<SquareImp> compo = new CompositeDungeon<SquareImp>(100000, 100000, 100000);
		
		CompositeDungeon<SquareImp> compo2 = new CompositeDungeon<SquareImp>(1000, 1000, 100);
		Level<SquareImp> level2 = new Level<SquareImp>(10,10,10,8);
		Shaft<SquareImp> shaft2 = new Shaft<SquareImp>(10,10,10,10,10,-4);
		
		CompositeDungeon<SquareImp> compo3 = new CompositeDungeon<SquareImp>(100, 100, 100);
		Shaft<SquareImp> shaft3 = new Shaft<SquareImp>(10, 10, 10, 9, 9, -5);
		
	
		
		try {
		
			compo3.addDungeonToCompositeDungeon(6, 6, 0, shaft3);
			compo2.addDungeonToCompositeDungeon(5, 5, 0, compo3);
			compo2.addDungeonToCompositeDungeon(3, 3, 0, level2);
			compo2.addDungeonToCompositeDungeon(4, 4, 0, shaft2);
			compo.addDungeonToCompositeDungeon(2, 2, 0, compo2);
			compo.addDungeonToCompositeDungeon(1, 1, 0, level);
			
		}
		catch (Exception e){
			e.printStackTrace();
		}
		
		assertEquals(shaft2.getRoot(), compo);
		shaft2.terminate();
		assertFalse(compo2.getListOfDungeons().contains(shaft2));
		
		
			
	}
	
	@Test
	public final void iteratortemperatureTuest() throws IllegalDimensionException{
		CompositeDungeon<SquareImp> compo = new CompositeDungeon<SquareImp>(100000,10000,10000);
		
		Level<SquareImp> level = new Level<SquareImp>(10,10,10,5);
		
		CompositeDungeon<SquareImp> compo2 = new CompositeDungeon<SquareImp>(1000, 1000, 100);
		Level<SquareImp> level2 = new Level<SquareImp>(10,10,10,8);
		Shaft<SquareImp> shaft2 = new Shaft<SquareImp>(10,10,10,10,10,-4);
		
		CompositeDungeon<SquareImp> compo3 = new CompositeDungeon<SquareImp>(100, 100, 100);
		Shaft<SquareImp> shaft3 = new Shaft<SquareImp>(10, 10, 10, 9, 9, -5);
		
		try {
		
			compo3.addDungeonToCompositeDungeon(6, 6, 0, shaft3);
			compo2.addDungeonToCompositeDungeon(5, 5, 0, compo3);
			compo2.addDungeonToCompositeDungeon(3, 3, 0, level2);
			compo2.addDungeonToCompositeDungeon(4, 4, 0, shaft2);
			compo.addDungeonToCompositeDungeon(2, 2, 0, compo2);
			compo.addDungeonToCompositeDungeon(1, 1, 0, level);
			
			PlainSquare plain = new PlainSquare();
			PlainSquare plain3 = new PlainSquare();
			
			plain.setMaterial(false);
			plain3.setMaterial(false);
			
			plain.setTemperature(500, Temperature.CELCIUS);
			plain3.setTemperature(800, Temperature.CELCIUS);
			
			PlainSquare s2 = new PlainSquare();
			s2.setMaterial(false);
			shaft2.addSquareToDungeon(10, 10, 1, s2);
			
			shaft3.addSquareToDungeon(9, 9, 0, plain3);
			level.addSquareToDungeon(1, 1, 5, plain);
			
		} catch (IllegalDungeonException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println(compo.getAllDegreeSquares(new PlainSquare(),200, Temperature.CELCIUS));
	
}
}
